import os

# 指定目标目录
input_directory = '/root/data/random_sample_filtered'

# 获取所有子文件夹并按名称排序
subfolders = [f.path for f in os.scandir(input_directory) if f.is_dir()]
subfolders.sort()

# 重命名子文件夹
for index, folder in enumerate(subfolders, start=1):
    # 构建新的文件夹名称，格式为 00001, 00002, ...
    new_folder_name = f"{index:05d}"
    new_folder_path = os.path.join(input_directory, new_folder_name)
    os.rename(folder, new_folder_path)
    print(f"Renamed {folder} to {new_folder_path}")

print('Renaming of subfolders completed.')

